package com.ibytecode.client;

import javax.naming.Context;
import javax.naming.NamingException;

import com.ibytecode.business.HelloWorld;
import com.ibytecode.businesslogic.HelloWorldBean;
import com.ibytecode.clientutility.ClientUtility;

public class EJBApplicationClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HelloWorld bean = doLookup();
		System.out.println(bean.sayHello());

	}

	private static HelloWorld doLookup() {
		Context ctx = null;
		HelloWorld bean = null;
		try{
			ctx = new ClientUtility().getInitialContext();
			String lookupName = getLookupName();
			bean = (HelloWorld) ctx.lookup(lookupName);
		} catch (NamingException e){e.printStackTrace();}
		return bean;
	}

	private static String getLookupName() {
		String appName = "";
		String moduleName = "HelloWorldSessionBean";
		String distinctName = "";
		String beanName = HelloWorldBean.class.getSimpleName();
		final String interfaceName = HelloWorld.class.getName();
		String name = "ejb:" + appName + moduleName + "/" +
				distinctName + beanName + "!" + interfaceName;
		return name;
	}

}
